package com.jigsaw.model;

import javax.persistence.*;
import java.util.Set;

/**
 * Created by Jigsaw on 2016/4/4.
 */
@Entity
@Table(name = "movies_info", schema = "movies", catalog = "")
public class MoviesInfoEntity {
    private int mid;
    private String title;
    private String rating;
    private String image;
    private String director;
    private String actors;
    private String longTime;
    private String des;
    private Integer readTime;
    private MoviesCateEntity cateById;
    private Set<UserEntity> userById;

    @Id
    @Column(name = "mid", nullable = false)
    public int getMid() {
        return mid;
    }

    public void setMid(int mid) {
        this.mid = mid;
    }

    @Basic
    @Column(name = "title", nullable = false, length = 512)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Basic
    @Column(name = "rating", nullable = true, length = 8)
    public String getRating() {
        return rating;
    }

    public void setRating(String rating) {
        this.rating = rating;
    }

    @Basic
    @Column(name = "image", nullable = true, length = 512)
    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    @Basic
    @Column(name = "director", nullable = true, length = 256)
    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    @Basic
    @Column(name = "actors", nullable = true, length = 1024)
    public String getActors() {
        return actors;
    }

    public void setActors(String actors) {
        this.actors = actors;
    }

    @Basic
    @Column(name = "long_time", nullable = true, length = 64)
    public String getLongTime() {
        return longTime;
    }

    public void setLongTime(String longTime) {
        this.longTime = longTime;
    }

    @Basic
    @Column(name = "des", nullable = true, length = 6000)
    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    @Basic
    @Column(name = "read_time", nullable = true)
    public Integer getReadTime() {
        return readTime;
    }

    public void setReadTime(Integer readTime) {
        this.readTime = readTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MoviesInfoEntity that = (MoviesInfoEntity) o;

        if (mid != that.mid) return false;
        if (title != null ? !title.equals(that.title) : that.title != null) return false;
        if (rating != null ? !rating.equals(that.rating) : that.rating != null) return false;
        if (image != null ? !image.equals(that.image) : that.image != null) return false;
        if (director != null ? !director.equals(that.director) : that.director != null) return false;
        if (actors != null ? !actors.equals(that.actors) : that.actors != null) return false;
        if (longTime != null ? !longTime.equals(that.longTime) : that.longTime != null) return false;
        if (des != null ? !des.equals(that.des) : that.des != null) return false;
        if (readTime != null ? !readTime.equals(that.readTime) : that.readTime != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = mid;
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (rating != null ? rating.hashCode() : 0);
        result = 31 * result + (image != null ? image.hashCode() : 0);
        result = 31 * result + (director != null ? director.hashCode() : 0);
        result = 31 * result + (actors != null ? actors.hashCode() : 0);
        result = 31 * result + (longTime != null ? longTime.hashCode() : 0);
        result = 31 * result + (des != null ? des.hashCode() : 0);
        result = 31 * result + (readTime != null ? readTime.hashCode() : 0);
        return result;
    }

    @ManyToOne
    @JoinColumn(name = "cate_id", referencedColumnName = "cid", nullable = false)
    public MoviesCateEntity getCateById() {
        return cateById;
    }

    public void setCateById(MoviesCateEntity cateById) {
        this.cateById = cateById;
    }

    @ManyToMany
    @JoinTable(name = "movies_user", catalog = "", schema = "movies", joinColumns = @JoinColumn(name = "rmid", referencedColumnName = "mid", nullable = false), inverseJoinColumns = @JoinColumn(name = "ruid", referencedColumnName = "uid", nullable = false))
    public Set<UserEntity> getUserById() {
        return userById;
    }

    public void setUserById(Set<UserEntity> userById) {
        this.userById = userById;
    }
}
